import React,{lazy} from 'react'
import {Navigate} from 'react-router-dom'
const Home=lazy(()=>import('../pages/home'))
const List=lazy(()=>import('../pages/list'))
const User=lazy(()=>import('../pages/user'))
const Set=lazy(()=>import('../pages/set'))
const Login=lazy(()=>import('../pages/login'))
const Layout=lazy(()=>import('../mainLayout'))
let list=[{
    path:'/',
    element:<Navigate to='/home'></Navigate>
},{
    path:'/home',
    name:'首页',
    element:<Home></Home>
},{
    path:'/list',
    name:'列表',
    element:<List></List>
},{
    path:'/user',
    name:'我的',
    element:<User></User>
},{
    path:'/set',
    name:'设置',
    element:<Set></Set>,
    meta:'aindmi'
}]
export const router=()=>{
    const token=localStorage.getItem('token')
    const data=list.filter(v=>{
        if(!v.meta)return true
        if(v.meta===token){
            return true
        }
    })
    return data
}
export default [{
    path:'/',
    element:<Layout></Layout>,
    children:router()
},{
    path:'/login',
    element:<Login></Login>
},]